<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>

<html lang="en">

<title>投资记录--爱钱帮</title>
<!-- 右侧边栏start -->
<%@include file="/WEB-INF/jsp/common/navigationRight.jsp"%>
<!-- 右侧边栏end -->


<!-- headerStart -->
<%@include file="/WEB-INF/jsp/common/head.jsp"%>
<!-- headerEnd -->

<%@include file="/WEB-INF/jsp/common/navigationLeft.jsp"%>
<!--公用提示框start-->

    <script>
        // 		$(document).ready(function(){
        var href = window.location.href;
        var search = window.location.search;
        $('.m2-asideListitem ul a').each(function () {
            if ($(this).prop('href') + search == href) {
                if ($(this).prop('href') == "/usercenter-wangbaoqiang" || $(this).prop('href') == "/usercenter-sirendingqi") {
                } else {
                    $(this).parent().parent('ul').show();
                    $(this).parent().parent('ul').prev('a').removeClass('m2-aside-item');
                    $(this).parent().parent('ul').prev('a').addClass('m2-aside-cur');
                    $(this).css('text-decoration', 'underline');
                    $(this).css('color', '#0996CC');
                }
            }
        });
        $('.m2-asideListitem a:not(.m2-asideListitem ul a)').each(function () {
            if ($(this).prop('href') + search == href) {
                if ($(this).prop('href').search("usercenter-wangbaoqiang") > -1) {
                    $(this).removeClass('m2-aside-wbq');
                    $(this).addClass('m2-aside-cur');
                } else if ($(this).prop('href').search("usercenter-sirendingqi") > -1) {
                    $(this).removeClass('m2-aside-wbq');
                    $(this).addClass('m2-aside-cur');
                } else {
                    $(this).removeClass('m2-aside-item');
                    $(this).addClass('m2-aside-cur');
                }
            }
        });
        $('.m2-asideListitem a:not(.m2-asideListitem ul a)').click(function () {
            if ($(this).prop('href') == '') {
                $(this).siblings('ul').slideToggle();
                $(this).parent().siblings('.m2-asideListitem').children('.m2-aside-secItem').slideUp();
            }
        });
        // 		});
    </script>

    <div class="m2-userTransfer-con">
        <div class="m2-userTrans-head">
            <h3><i></i>债权转让</h3>
        </div>
        <div class="m2-manage-search">
            <div class="m2-manage-search-selector">
                <ul class="m2-manageSearchsel-type">
                    <li>交易类型：</li>
                    <li class="m2-manageSearchsel-link"><span class="m2-userTrans-btn1 m2-manSealink-sel" onclick="displayCan()" status="0">可转让债权</span></li>
                    <li class="m2-manageSearchsel-link"><span class="m2-userTrans-btn2 m2-manSealink-unsel" onclick="displayIng()" status="1">转让中的债权</span></li>
                    <li class="m2-manageSearchsel-link"><span class="m2-userTrans-btn3 m2-manSealink-unsel" onclick="displayDone()" status="2">已转让的债权</span></li>
                    <li class="m2-manageSearchsel-link"><span class="m2-userTrans-btn4 m2-manSealink-unsel" onclick="displaySubscribe()" status="3">已认购的债权</span></li>
                </ul>
                <ul class="m2-manageSearchsel-time">
                    <li>投资时间：</li>
                    <li class="m2-manageSearchsel-link"><span class="m2-manSealink-sel" onclick="displayAllDay(10000)" data-days='10000'>全部</span></li>
                    <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" onclick="displayAllDay(7)" data-days='7'>最近7天</span></li>
                    <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" onclick="displayAllDay(30)" data-days='30'>一个月</span></li>
                    <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" onclick="displayAllDay(90)"data-days='90'>三个月</span></li>
                    <li>从<input id="m2-manSeadate-start" type="text"></li>
                    <li>到<input id="m2-manSeadate-end" onblur="searchDATE()" type="text"></li>
                </ul>
                <!--table1-->
                <table class="m2-userTrans-tab1 m2-manageResult" cellpadding="0" cellspacing="0">
                    <tr class="m2-manageResult-head">
                        <th style="width:100px;">项目名称</th>
                        <th style="width:90px;">年化收益</th>
                        <th style="width:120px;">投资金额</th>
                        <th style="width:120px;">剩余债权</th>
                        <th style="width:90px;">剩余时间</th>
                        <th style="width:120px;">投资日期</th>
                        <th class="m2-userTranstable-tit" style="width:100px;">操作</th>
                    </tr>
                    <c:forEach items="${InvestmentList}" var="investments" varStatus="row">
                        <tr class="m2-manageResult-sum">
                            <th style="width:200px;">${investments.proName}</th>
                            <th style="width:90px;">${investments.rate}</th>
                            <th style="width:90px;">${investments.investAmount}</th>
                            <th style="width:90px;">${investments.restAmount}</th>
                            <th style="width:90px;">${investments.restDay}</th>
                            <th style="width:150px;"><fmt:formatDate value="${investments.investDate}" pattern="yyyy-MM-dd"/></th>
                            <th class="m2-userTranstable-tit" style="width:90px;"><button onclick="showTransfer(${investments.investId})">转让</button></th>
                        </tr>
                    </c:forEach>

                    <tr class="m2-manageResult-sum" style="display: none;">
                        <td colspan="7"><span class="m2-manageResult-more" data-type='1'>加载更多</span></td>
                    </tr>

                </table>
                <!--table2-->
                <table style="display:none;"class="m2-userTrans-tab2 m2-manageResult" cellpadding="0" cellspacing="0">
                    <tr class="m2-manageResult-head">
                        <th style="width:75px;">项目名称</th>
                        <th style="width:80px;">收益率</th>
                        <th style="width:100px;">转让金额</th>
                        <th style="width:100px;">转让价格</th>
                        <th style="width:110px;">申请时间</th>
                        <th style="width:110px;">已承接金额</th>

                    </tr>

                    <tr class="m2-manageResult-sum" style="display: none;">
                        <td colspan="8"><span class="m2-manageResult-more" data-type='2'>加载更多</span></td>
                    </tr>
                </table>
                <!--table3-->
                <table style="display:none;"class="m2-userTrans-tab3 m2-manageResult" cellpadding="0" cellspacing="0">
                    <tr class="m2-manageResult-head">
                        <th style="width:200px;">项目名称</th>
                        <th style="width:100px;">转让金额</th>
                        <th style="width:100px;">承接价格</th>
                        <th style="width:100px;">承接收益率</th>
                        <th style="width:150px;">承接时间</th>
                    </tr>
                    <tr class="m2-manageResult-sum" style="display: none;">
                        <td colspan="8"><span class="m2-manageResult-more" data-type='3'>加载更多</span></td>
                    </tr>
                </table>
                <!--table4-->
                <table style="display:none;"class="m2-userTrans-tab4 m2-manageResult" cellpadding="0" cellspacing="0">
                    <tr class="m2-manageResult-head">
                        <th style="width:200px;">项目名称</th>
                        <th style="width:100px;">认购金额</th>
                        <th style="width:100px;">预期收益</th>
                        <th style="width:150px;">承接时间</th>
                        <th style="width:100px;">剩余时间</th>
                    </tr>

                    <tr class="m2-manageResult-sum" style="display: none;">
                        <td colspan="8"><span class="m2-manageResult-more" data-type='4'>加载更多</span></td>
                    </tr>
                </table>
            </div>
        </div>
    </div>

                <div style="margin-left: 500px ; margin-top: 50px;font-size: 20px">
                    <input type="hidden" value="${ph.currentPageNo }" id="currentPage" />
                    <input type="hidden" value="${ph.totalPageCount }" id="totalPages" />
                    当前页数:[<span id="spcp">1</span>/<span id="sptp">1</span>]&nbsp;
                    <a href="javascript:void(0)" class="previous" id="first" style="color:gray">首页</a>
                    <a href="javascript:void(0)" class="previous" id="previous" style="color:gray">上一页</a>
                    <a href="javascript:void(0)" class="next" id="next" style="color:blue">下一页</a>
                    <a href="javascript:void(0)" class="next" id="last" style="color:blue">末页</a>
                    跳转到：<input type="text" value="" id="jumpPageNo" size="10"/><button style="width: 50px" id="jumpGo">GO</button>
                </div>
</div>


<input type="hidden" id="userID" value="${userSession.userId}">









<script type="text/javascript">







    var start = Array(1, 1, 1, 1, 1);
    var time1 = '';
    var time2 = '';
    var days = 0;
    var tdata = {};
    var getrate_tag = false;
    var transfer_num = '';
    var transfer_price = '';

    //显示一段时间的债权
    function searchDATE(){
        var status = $(".m2-manage-search-selector .m2-manSealink-sel").attr("status")
        var id = $("#userID").val();
        var begin = $("#m2-manSeadate-start").val();
        var end = $("#m2-manSeadate-end").val();
        $.ajax({
            "url":"/lzy/SearchForTime",
            "type":"post",
            "dataType":"json",
            "data":{"id":id,"status":status,"begin":begin,"end":end},
            "success":function (data) {
                if(0 == status ){
                    var InvestmentList = $(data.InvestmentList);
                    var cgstr="";
                    InvestmentList.each(function () {
                        var date = getMyDate(this.investDate);
                        cgstr += "<tr class='m2-manageResult-sum' style='width:1000px'>"
                        cgstr += "<th width='200px';>"+this.proName+"</th>"
                        cgstr += "<th style='width:90px;'>"+this.rate+"</th>"
                        cgstr += "<th style='width:90px;'>"+this.investAmount+"</th>"
                        cgstr += "<th style='width:90px;'>"+this.restAmount+"</th>"
                        cgstr += "<th style='width:90px;'>"+this.restDay+"</th>"
                        cgstr += "<th style='width:150px;'>"+date+"</th>"
                        cgstr += "<th style='width:90px;'><button onclick='showTransfer("+this.investId+")'>转让</button></th>"
                        cgstr += "</tr>"
                    })
                    $(".m2-manageResult-sum").remove();
                    $(".m2-manageResult-head").after(cgstr);
                }else if(1 == status){
                    var CreditorList1 = $(data.CreditorList1);
                    var cgstr="";
                    CreditorList1.each(function () {
                        var date = getMyDate(this.transferTime);
                        cgstr += "<tr class='m2-manageResult-sum'>"
                        cgstr += "<th style='width:200px;'>"+this.proName+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.currentRate+"</th>"
                        cgstr += "<th style='width:120px;'>"+this.subscribeMoney+"</th>"
                        cgstr += "<th style='width:120px;'>"+this.transferMonry+"</th>"
                        cgstr += "<th style='width:180px;'>"+date+"</th>"
                        cgstr += "<th style='width:120px;'>"+this.currentMoney+"</th>"
                        cgstr += "</tr>"
                    })

                    $(".m2-manageResult-sum").remove();
                    $(".m2-manageResult-head").after(cgstr);
                }else if(2 == status){
                    var CreditorList2 = $(data.CreditorList2);
                    var cgstr="";
                    CreditorList2.each(function () {
                        var date = getMyDate(this.modifyDate);
                        cgstr += "<tr class='m2-manageResult-sum'>"
                        cgstr += "<th style='width:200px;'>"+this.proName+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.subscribeMoney+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.transferMonry+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.getRate+"</th>"
                        cgstr += "<th style='width:150px;'>"+date+"</th>"
                        cgstr += "</tr>"
                    })

                    $(".m2-manageResult-sum").remove();
                    $(".m2-manageResult-head").after(cgstr);
                }else if(3 == status){
                    var receptList = $(data.receptList);
                    var cgstr="";
                    receptList.each(function () {
                        var date = getMyDate(this.receptTime);
                        cgstr += "<tr class='m2-manageResult-sum'>"
                        cgstr += "<th style='width:200px;'>"+this.proName+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.receptMoney+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.currentRate+"</th>"
                        cgstr += "<th style='width:150px;'>"+date+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.restDay+"</th>"
                        cgstr += "</tr>"
                    })

                    $(".m2-manageResult-sum").remove();
                    $(".m2-manageResult-head").after(cgstr);
                }

            } ,
            "error":function (e) {
                alert(e.toString());
            }
        });

    }



    //显示可转让债权
    function displayCan() {
        var id = $("#userID").val();
        var querytime = $(".m2-manageSearchsel-time .m2-manSealink-sel").attr("data-days");

        $.ajax({
            "url":"/lzy/transferCan",
            "type":"post",
            "dataType":"json",
            "data":{"id":id,"querytime":querytime},
            "success":function (data) {
                var InvestmentList = $(data.InvestmentList);
                var cgstr="";
                InvestmentList.each(function () {
                    var date = getMyDate(this.investDate);
                    cgstr += "<tr class='m2-manageResult-sum' style='width:1000px'>"
                    cgstr += "<th width='200px';>"+this.proName+"</th>"
                    cgstr += "<th style='width:90px;'>"+this.rate+"</th>"
                    cgstr += "<th style='width:90px;'>"+this.investAmount+"</th>"
                    cgstr += "<th style='width:90px;'>"+this.restAmount+"</th>"
                    cgstr += "<th style='width:90px;'>"+this.restDay+"</th>"
                    cgstr += "<th style='width:150px;'>"+date+"</th>"
                    cgstr += "<th style='width:90px;'><button onclick='showTransfer("+this.investId+")'>转让</button></th>"
                    cgstr += "</tr>"
                })

                $(".m2-manageResult-sum").remove();
                $(".m2-manageResult-head").after(cgstr);
            } ,
            "error":function (e) {

            }
        });
    }





    //根据时间显示债权
    function displayAllDay(DateTime) {

        var status = $(".m2-manage-search-selector .m2-manSealink-sel").attr("status")
        var id = $("#userID").val();
        $.ajax({
            "url":"/lzy/SearchByTime",
            "type":"post",
            "dataType":"json",
            "data":{"id":id,"status":status,"DateTime":DateTime},
            "success":function (data) {
                if(0 == status ){
                    var InvestmentList = $(data.InvestmentList);
                    var cgstr="";
                    InvestmentList.each(function () {
                        var date = getMyDate(this.investDate);
                        cgstr += "<tr class='m2-manageResult-sum' style='width:1000px'>"
                        cgstr += "<th width='200px';>"+this.proName+"</th>"
                        cgstr += "<th style='width:90px;'>"+this.rate+"</th>"
                        cgstr += "<th style='width:90px;'>"+this.investAmount+"</th>"
                        cgstr += "<th style='width:90px;'>"+this.restAmount+"</th>"
                        cgstr += "<th style='width:90px;'>"+this.restDay+"</th>"
                        cgstr += "<th style='width:150px;'>"+date+"</th>"
                        cgstr += "<th style='width:90px;'><button onclick='showTransfer("+this.investId+")'>转让</button></th>"
                        cgstr += "</tr>"
                    })
                    $(".m2-manageResult-sum").remove();
                    $(".m2-manageResult-head").after(cgstr);
                }else if(1 == status){
                    var CreditorList1 = $(data.CreditorList1);
                    var cgstr="";
                    CreditorList1.each(function () {
                        var date = getMyDate(this.transferTime);
                        cgstr += "<tr class='m2-manageResult-sum'>"
                        cgstr += "<th style='width:200px;'>"+this.proName+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.currentRate+"</th>"
                        cgstr += "<th style='width:120px;'>"+this.subscribeMoney+"</th>"
                        cgstr += "<th style='width:120px;'>"+this.transferMonry+"</th>"
                        cgstr += "<th style='width:180px;'>"+date+"</th>"
                        cgstr += "<th style='width:120px;'>"+this.currentMoney+"</th>"
                        cgstr += "</tr>"
                    })

                    $(".m2-manageResult-sum").html("");
                    $(".m2-manageResult-head").after(cgstr);
                }else if(2 == status){
                    var CreditorList2 = $(data.CreditorList2);
                    var cgstr="";
                    CreditorList2.each(function () {
                        var date = getMyDate(this.modifyDate);
                        cgstr += "<tr class='m2-manageResult-sum'>"
                        cgstr += "<th style='width:200px;'>"+this.proName+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.subscribeMoney+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.transferMonry+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.getRate+"</th>"
                        cgstr += "<th style='width:150px;'>"+date+"</th>"
                        cgstr += "</tr>"
                    })

                    $(".m2-manageResult-sum").remove();
                    $(".m2-manageResult-head").after(cgstr);
                }else if(3 == status){
                    var receptList = $(data.receptList);
                    var cgstr="";
                    receptList.each(function () {
                        var date = getMyDate(this.receptTime);
                        cgstr += "<tr class='m2-manageResult-sum'>"
                        cgstr += "<th style='width:200px;'>"+this.proName+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.receptMoney+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.currentRate+"</th>"
                        cgstr += "<th style='width:150px;'>"+date+"</th>"
                        cgstr += "<th style='width:100px;'>"+this.restDay+"</th>"
                        cgstr += "</tr>"
                    })

                    $(".m2-manageResult-sum").remove();
                    $(".m2-manageResult-head").after(cgstr);
                }

            } ,
            "error":function (e) {

            }
        });
    }



    //layer显示
    function showTransfer(investId){



        window.location.href="${pageContext.request.contextPath}/lzy/TrsnsferInvestment?investId="+investId;


    }


    //时间转换
    function getMyDate(str){
        var oDate = new Date(str),
            oYear = oDate.getFullYear(),
            oMonth = oDate.getMonth()+1,
            oDay = oDate.getDate(),
            oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay);//最后拼接时间
        return oTime;
    };

    function getzf(num){
        if(parseInt(num) < 10){
            num = '0'+num;
        }
        return num;
    }


   //显示转让中债权
   function displayIng(){
       var id = $("#userID").val();
       var querytime = $(".m2-manageSearchsel-time .m2-manSealink-sel").attr("data-days");
      $.ajax({
        "url":"/lzy/transfering",
        "type":"post",
        "dataType":"json",
        "data":{"id":id,"querytime":querytime},
        "success":function (data) {
            var CreditorList = $(data.CreditorList);
            var cgstr="";
            CreditorList.each(function () {
                var date = getMyDate(this.transferTime);
                cgstr += "<tr class='m2-manageResult-sum'>"
                cgstr += "<th style='width:200px;'>"+this.proName+"</th>"
                cgstr += "<th style='width:100px;'>"+this.currentRate+"</th>"
                cgstr += "<th style='width:120px;'>"+this.subscribeMoney+"</th>"
                cgstr += "<th style='width:120px;'>"+this.transferMonry+"</th>"
                cgstr += "<th style='width:180px;'>"+date+"</th>"
                cgstr += "<th style='width:120px;'>"+this.currentMoney+"</th>"
                cgstr += "</tr>"
            })

            $(".m2-manageResult-sum").remove();
            $(".m2-manageResult-head").after(cgstr);
        } ,
        "error":function (e) {

        }
      });
   }



   //显示已转让债权
   function displayDone(){
       var id = $("#userID").val();
       var querytime = $(".m2-manageSearchsel-time .m2-manSealink-sel").attr("data-days");
       $.ajax({
           "url":"/lzy/transferDone",
           "type":"post",
           "dataType":"json",
           "data":{"id":id,"querytime":querytime},
           "success":function (data) {
               var CreditorList = $(data.CreditorList);
               var cgstr="";
               CreditorList.each(function () {
                   var date = getMyDate(this.modifyDate);
                   cgstr += "<tr class='m2-manageResult-sum'>"
                   cgstr += "<th style='width:200px;'>"+this.proName+"</th>"
                   cgstr += "<th style='width:100px;'>"+this.subscribeMoney+"</th>"
                   cgstr += "<th style='width:100px;'>"+this.transferMonry+"</th>"
                   cgstr += "<th style='width:100px;'>"+this.getRate+"</th>"
                   cgstr += "<th style='width:150px;'>"+date+"</th>"
                   cgstr += "</tr>"
               })

               $(".m2-manageResult-sum").remove();
               $(".m2-manageResult-head").after(cgstr);
           } ,
           "error":function (e) {

           }
       });
   }


   //显示已认购的债权
    function displaySubscribe(){
        var id = $("#userID").val();
        var querytime = $(".m2-manageSearchsel-time .m2-manSealink-sel").attr("data-days");
        $.ajax({
            "url":"/lzy/Subscribe",
            "type":"post",
            "dataType":"json",
            "data":{"id":id,"querytime":querytime},
            "success":function (data) {
                var receptList = $(data.receptList);
                var cgstr="";
                receptList.each(function () {
                    var date = getMyDate(this.receptTime);
                    cgstr += "<tr class='m2-manageResult-sum'>"
                    cgstr += "<th style='width:200px;'>"+this.proName+"</th>"
                    cgstr += "<th style='width:100px;'>"+this.receptMoney+"</th>"
                    cgstr += "<th style='width:100px;'>"+this.currentRate+"</th>"
                    cgstr += "<th style='width:150px;'>"+date+"</th>"
                    cgstr += "<th style='width:100px;'>"+this.restDay+"</th>"
                    cgstr += "</tr>"
                })

                $(".m2-manageResult-sum").remove();
                $(".m2-manageResult-head").after(cgstr);
            } ,
            "error":function (e) {

            }
        });
    }

    $(function () {
        //table切换
        tableChange();
        //时间切换
        timeChange();
        //日历
        ucDatepicker('#m2-manSeadate-start');
        ucDatepicker('#m2-manSeadate-end');
        //弹窗
        dialogFunc();
        //取数据
        getTransferData(0);
        //加载更多
        loadMore();
        //检查债转金额
        checkTransfer();
        //定向债转选择
        specialTrans();
    });
    //弹窗
    function dialogFunc() {
        $('.m2-userTrans-planBtn').click(function () {
            if ($(this).hasClass('m2-userTrans-upBtn')) {
                $(this).addClass('m2-userTrans-downBtn').removeClass('m2-userTrans-upBtn');
                $('.m2-userCommonconfirm-transInfo').show();
            } else if ($(this).hasClass('m2-userTrans-downBtn')) {
                $(this).removeClass('m2-userTrans-downBtn');
                $(this).addClass('m2-userTrans-upBtn');
                $('.m2-userCommonconfirm-transInfo').hide();
            }
        });
    }
    //table切换
    function tableChange() {
        $('.m2-manageSearchsel-type span').click(function () {
            $('.m2-manageSearchsel-type span').removeClass('m2-manSealink-sel');
            $('.m2-manageSearchsel-type span').addClass('m2-manSealink-unsel');
            $(this).removeClass('m2-manSealink-unsel');
            $(this).addClass('m2-manSealink-sel');
        });
        $('.m2-userTrans-btn1').click(function () {
            $('table.m2-userTrans-tab1').show();
            $('table.m2-userTrans-tab1').siblings('table').hide();
        });
        $('.m2-userTrans-btn2').click(function () {
            $('table.m2-userTrans-tab2').show();
            $('table.m2-userTrans-tab2').siblings('table').hide();
        });
        $('.m2-userTrans-btn3').click(function () {
            $('table.m2-userTrans-tab3').show();
            $('table.m2-userTrans-tab3').siblings('table').hide();
        });
        $('.m2-userTrans-btn4').click(function () {
            $('table.m2-userTrans-tab4').show();
            $('table.m2-userTrans-tab4').siblings('table').hide();
        });
    }
    //时间切换
    function timeChange() {
        $('.m2-manageSearchsel-time span').click(function () {
            $('#m2-manSeadate-start').val('');
            $('#m2-manSeadate-end').val('');
            time1 = '';
            time2 = '';
            $('.m2-manageSearchsel-time span').removeClass('m2-manSealink-sel');
            $('.m2-manageSearchsel-time span').addClass('m2-manSealink-unsel');
            $(this).removeClass('m2-manSealink-unsel');
            $(this).addClass('m2-manSealink-sel');
            resetData();
            days = $(this).data('days');
            getTransferData(0);
        });
    }
    //加载更多
    function loadMore() {
        $('.m2-manageResult-more').click(function () {
            var type = $(this).data('type');
            getTransferData(type);
        });
    }
    //获取数据
    function getTransferData(type) {

        $.ajax({
            url: "usercenter-Investcontrol-getTransferDataAjax",
            type: "POST",
            data: {
                time1: time1,
                time2: time2,
                days: days,
                type: type,
                start: start[type]
            },
            success: function (data) {
                processData(data);
            }
        });
    }
    //处理数据
    function processData(data) {
        var obj = eval('(' + data + ')');
        if (obj[1]['data'] || obj[1]['pages'] >= 0) {
            for (var i in obj[1]['data']) {
                var tr = '<tr class="m2-manageResult-item">';
                tr += '<td class="m2-userTransfer-proTit" title="' + obj[1]['data'][i]['borrow_name'] + '">' + obj[1]['data'][i]['borrow_name'] + '</td>';
                tr += '<td>' + obj[1]['data'][i]['borrow_interest_rate'] + '%</td>';
                tr += '<td>' + obj[1]['data'][i]['investor_capital'] + '元</td>';
                tr += '<td>' + obj[1]['data'][i]['left_capital'] + '元</td>';
                tr += '<td class="m2-userTransfer-timeLeft">';
                tr += '<span class="m2-userTransfer-timeLefttit">' + obj[1]['data'][i]['left_days'] + '天</span>';
                tr += '<div class="m2-userTransfer-timeHide">';
                tr += '<em class="m2-userTransferhide-arr"></em>';
                tr += '<em class="m2-userTransferhide-arrbg"></em>';
                tr += '<ul><li>投标时间：<span>' + obj[1]['data'][i]['invest_date'] + '</span></li>';
                tr += '<li>还款时间：<span>' + obj[1]['data'][i]['pay_date'] + '</span></li></ul></div></td>';
                tr += '<td>' + obj[1]['data'][i]['investor_interest'] + '元</td>';
                tr += '<td class="m2-userTrans-tdLink">';
                tr += '<a class="m2-userTransbtn-transfer" onclick="tranferDialog(' + obj[1]['data'][i]['id'] + ')">转让</a>';
                tr += '</td>';
                tr += '</tr>';
                if (obj[1]['data'][i]['id']) {
                    $('.m2-userTrans-tab1 .m2-manageResult-sum').before(tr);
                }
            }
            moreOrNo(obj[1]['pages'], 1);
        }
        if (obj[2]['data'] || obj[2]['pages'] >= 0) {
            for (var i in obj[2]['data']) {
                var tr = '<tr class="m2-manageResult-item">';
                tr += '<td class="m2-userTransfer-proTit" title="' + obj[2]['data'][i]['borrow_name'] + '">' + obj[2]['data'][i]['borrow_name'] + '</td>';
                tr += '<td>' + obj[2]['data'][i]['borrow_interest_rate'] + '%</td>';
                tr += '<td>' + obj[2]['data'][i]['transfer_capital'] + '元</td>';
                tr += '<td>' + obj[2]['data'][i]['plan_sale_price'] + '元</td>';
                tr += '<td>' + obj[2]['data'][i]['invest_date'] + '</td>';
                tr += '<td>' + obj[2]['data'][i]['end_date'] + '</td>';
                tr += '<td>' + obj[2]['data'][i]['progress'] + '%</td>';
                tr += '<td class="m2-userTrans-tdLink">';
                // tr += '<a class="m2-userTransbtn-change" onclick="tranferDialog(' + obj[2]['data'][i]['invest_id'] + ',' + obj[2]['data'][i]['plan_sale_price'] + ')">变更</a>';
                tr += '<a class="m2-userTransbtn-delete" onclick="delDialog(' + obj[2]['data'][i]['id'] + ')">删除</a></td>';
                tr += '</tr>';
                $('.m2-userTrans-tab2 .m2-manageResult-sum').before(tr);
            }
            moreOrNo(obj[2]['pages'], 2);
        }
        if (obj[3]['data'] || obj[3]['pages'] >= 0) {
            for (var i in obj[3]['data']) {
                var tr = '<tr class="m2-manageResult-item">';
                tr += '<td class="m2-userTransfer-proTit" title="' + obj[3]['data'][i]['borrow_name'] + '">' + obj[3]['data'][i]['borrow_name'] + '</td>';
                tr += '<td>' + obj[3]['data'][i]['investor_capital'] + '元</td>';
                tr += '<td>' + obj[3]['data'][i]['investor_capital_trans'] + '元</td>';
                tr += '<td>' + obj[3]['data'][i]['investor_interest'] + '</td>';
                tr += '<td>' + obj[3]['data'][i]['sold_date'] + '</td>';
                tr += '<td>' + obj[3]['data'][i]['end_date'] + '</td>';
                tr += '<td class="m2-userTrans-tdLink"><a href="/member-contracttrans-investor.shtml?id=' + obj[3]['data'][i]['encryptedid'] + '" target="_blank">合同</a>/ <a href="/Member-Contract-createAndSendPdfbyid?flag=1&id='+ obj[3]['data'][i]['encryptedid'] +'" target="_blank">下载</a></td>';
                tr += '</tr>';
                $('.m2-userTrans-tab3 .m2-manageResult-sum').before(tr);
            }
            moreOrNo(obj[3]['pages'], 3);
        }
        if (obj[4]['data'] || obj[4]['pages'] >= 0) {
            for (var i in obj[4]['data']) {
                var tr = '<tr class="m2-manageResult-item">';
                tr += '<td class="m2-userTransfer-proTit" title="' + obj[4]['data'][i]['borrow_name'] + '">' + obj[4]['data'][i]['borrow_name'] + '</td>';
                tr += '<td>' + obj[4]['data'][i]['investor_capital'] + '元</td>';
                tr += '<td>' + obj[4]['data'][i]['investor_capital_trans'] + '元</td>';
                tr += '<td>' + obj[4]['data'][i]['investor_interest'] + '</td>';
                tr += '<td>' + obj[4]['data'][i]['sold_date'] + '</td>';
                tr += '<td>' + obj[4]['data'][i]['end_date'] + '</td>';
                tr += '<td class="m2-userTrans-tdLink"><a href="/member-contracttrans-investor.shtml?id=' + obj[4]['data'][i]['encryptedid'] + '" target="_blank">合同</a>/ <a href="/Member-Contract-createAndSendPdfbyid?id='+ obj[4]['data'][i]['encryptedid'] +'" target="_blank">下载</a></td>';
                tr += '</tr>';
                $('.m2-userTrans-tab4 .m2-manageResult-sum').before(tr);
            }
            moreOrNo(obj[4]['pages'], 4);
        }
    }
    //加载更多，暂无数据
    function moreOrNo(pages, index) {
        if (pages > start[index]) {
            start[index]++;
            $('.m2-userTrans-tab' + index + ' .m2-manageResult-sum').show();
        } else {
            $('.m2-userTrans-tab' + index + ' .m2-manageResult-sum').hide();
        }
        if (pages == 0) {
            $('.m2-userTrans-tab' + index + ' .m2-manageResult-sum').before('<tr class="m2-manageResult-item"><td colspan="8">暂无数据</td></tr>');
        }
    }
    //债转弹窗
    function tranferDialog(id, price) {

        if ($('.m2-userTrans-planBtn').hasClass('m2-userTrans-downBtn')) {
            $('.m2-userTrans-planBtn').removeClass('m2-userTrans-downBtn');
            $('.m2-userTrans-planBtn').addClass('m2-userTrans-upBtn');
            $('.m2-userCommonconfirm-transInfo').hide();
        }
        clearData();
        $('#dialog-t-bg').show();
        $('#dialog-t-div').show();
        $.ajax({
            url: "/usercenter-Investcontrol-getTransferDetail",
            type: "POST",
            data: {
                invest_id: id
            },
            success: function (data) {
                var obj = eval('(' + data + ')');
                $('#transfer_num').val(obj['investor_capital']);
                transfer_num = obj['investor_capital'];
                $('#transfer_num').data('id', obj['id']);
                $('#transfer_num').data('max', obj['investor_capital']);
                if (price) {
                    $('#transfer_price').val(price.toFixed(2));
                } else {
                    $('#transfer_price').val('');
                }
                if (obj['vip'] == 1){
                    $('#dia-fee').text('0元');
                }else {
                    $('#dia-fee').text((Math.round(obj['investor_capital'] * 0.5) / 100) + '元');
                }

                $('#dia-invest').text(obj['investor_capital'] + '元');
                $('#dia-investrate').text(obj['borrow_interest_rate'] + '%');
                $('#dia-investdays').text(obj['total_days'] + '天');
                $('#dia-leftdays').text(obj['left_days'] + '天');
                $('#dia-receive').text(obj['receive_interest'] + '元');
                $('#dia-leftinterest').text(obj['left_interest'] + '元');
                $('#dia-transferrate').text('0%');
                $('#dia-getrate').text('0%');
                if (obj['is_special'] == 1) {
                    $('#specialtrans').prop('checked', true);
                    $('#transfer_price').prop('readOnly', true);
                } else {
                    $('#specialtrans').prop('checked', false);
                    $('#transfer_price').prop('readOnly', false);
                }
                if (obj['can_special'] == 1) {
                    $('#specialtrans').prop('disabled', false);
                    $('#specialtransli').show();
                    if (!price) {
                        $('#specialtrans').prop('checked', true);
                        $('#transfer_price').prop('readOnly', true);
                        $('#transfer_price').val(transfer_num);
                        $('#dia-fee').text('0元');
                        transfer_price = transfer_num;
                        $('#dia-transferrate').text($('#dia-investrate').text());
                        $('#dia-getrate').text($('#dia-investrate').text());
                        getrate_tag = true;
                    }
                } else {
                    $('#specialtrans').prop('disabled', true);
                    $('#specialtransli').hide();
                }
                for (var i in obj['list']) {
                    var li = '<li><span>支付时间：</span>';
                    li += '<span style="margin-right:50px;">' + obj['list'][i]['date'] + '</span>';
                    li += '<span>支付利息：</span>';
                    li += '<span>' + obj['list'][i]['interest'] + '元</span></li>';
                    $('.m2-userCommonconfirm-transInfo').append(li);
                }
            }
        });
    }
    //定向债转选择
    function specialTrans() {
        $('#specialtrans').click(function () {
            if ($('#specialtrans').prop('checked')) {
                $('#transfer_price').prop('readOnly', true);
                $('#transfer_price').val(transfer_num);
                $('#dia-fee').text('0元');
                transfer_price = transfer_num;
                $('#dia-transferrate').text($('#dia-investrate').text());
                $('#dia-getrate').text($('#dia-investrate').text());
                getrate_tag = true;
            } else {
                $('#transfer_price').prop('readOnly', false);
                $('#dia-fee').text((Math.round(transfer_num * 0.5) / 100) + '元');
                $('#dia-transferrate').text('0%');
                $('#dia-getrate').text('0%');
            }
        });
    }
    //清除弹窗数据
    function clearData() {
        $('.m2-userCommonconfirm-transInfo').html('');
        $('#transfer_error2').html('');
        $('#transfer_num').val('');
        $('#transfer_num').data('id', '');
        $('#transfer_num').data('max', '');
        $('#transfer_price').val('');
        $('#transfer_price').prop('readOnly', false);
        $('#dia-fee').text('');
        $('#dia-invest').text('');
        $('#dia-investrate').text('');
        $('#dia-investdays').text('');
        $('#dia-leftdays').text('');
        $('#dia-receive').text('');
        $('#dia-leftinterest').text('');
        $('#dia-transferrate').text('');
        $('#dia-getrate').text('');
        $('#specialtrans').prop('disabled', true);
        $('#specialtrans').prop('checked', false);
        $('#specialtransli').hide();
    }
    //债转金额检查
    function checkTransfer() {

        $('#transfer_num').keyup(function () {
            if ($('#transfer_num').val() == '') {
                $('#dia-fee').text('0元');
                $('#transfer_error1').text('');
            } else if (isNaN($('#transfer_num').val())) {
                $('#transfer_num').val(transfer_num);
            } else if (Number($('#transfer_num').val()) > Number($('#transfer_num').data('max'))) {
                $('#transfer_num').val(transfer_num);
                $('#transfer_error1').text('债转金额过大');
            } else {
                $('#transfer_error1').text('');
                transfer_num = $('#transfer_num').val();
                $('#dia-fee').text(Math.round(transfer_num * 0.5) / 100 + '元');
            }
        });
        $('#transfer_price').keyup(function () {
            getrate_tag = false;
            var floor_price = Math.round(90 * transfer_num) / 100;
            var ceil_price = Math.round(110 * transfer_num) / 100;
            if ($('#transfer_price').val() == '') {
                transfer_price = '';
                $('#transfer_error2').text('');
            } else if (isNaN($('#transfer_price').val())) {
                $('#transfer_price').val(transfer_price);
            } else if (Number($('#transfer_price').val()) > ceil_price || Number($('#transfer_price').val()) < floor_price) {
                transfer_price = $('#transfer_price').val();
                $('#transfer_error2').html('<br>转让价格应为转让金额的90%-110%,即' + floor_price + '元-' + ceil_price + '元');
            } else {
                $('#transfer_error2').text('');
                transfer_price = $('#transfer_price').val();
            }
        });
        $('#transfer_num').blur(getBuyRate);
        $('#transfer_price').blur(getBuyRate);
    }
    //获取承接年化
    function getBuyRate() {

        if (transfer_num && transfer_price) {
            $.ajax({
                url: "/usercenter-Investcontrol-transfercalculate_new",
                type: "POST",
                data: {
                    transferMoney: transfer_num,
                    planPrice: transfer_price,
                    investid: $('#transfer_num').data('id')
                },
                success: function (data) {
                    var obj = eval('(' + data + ')');
                    $('#dia-getrate').text(obj['received_interestRate'] + '%');
                    $('#dia-transferrate').text(obj['planInterest'] + '%');
                    if (Number(obj['received_interestRate']) >= 0) {
                        getrate_tag = true;
                        $('#transfer_error2').html('');
                    } else {
                        $('#transfer_error2').html('<br>承接年化不能小于0%');
                    }
                }
            });
        }
    }
    //确认债转
    function confirmTransfer() {

        if (transfer_num && transfer_price && getrate_tag) {
            if (transfer_price <= 1.1 * transfer_num && transfer_price >= 0.9 * transfer_num) {
                $('.m2-userCentercommon-confirm').hide();
                $('.m2-userCentercommon-bg').hide();
                $.ajax({
                    url: "/usercenter-Investcontrol-transferoperate",
                    type: "POST",
                    data: {
                        is_special: $('#specialtrans').prop('checked'),
                        transferMoney: transfer_num,
                        planPrice: transfer_price,
                        invest_id: $('#transfer_num').data('id')
                    },
                    success: function (data) {
                        var obj = eval('(' + data + ')');
                        infoDialog(obj['message']);
                        if (obj['status'] == 1) {
                            resetData();
                            getTransferData(0);
                        }
                    }
                });
            }
        }
    }
    //删除弹窗
    var trid = -1;
    function delDialog(id) {
        $('#dialog-del-bg').show();
        $('#dialog-del-div').show();
        trid = id;
    }
    function confirmDel() {

        $.ajax({
            url: "/usercenter-Investcontrol-deleteTransfer",
            type: "POST",
            data: {
                trId: trid
            },
            success: function (data) {
                var obj = eval('(' + data + ')');
                infoDialog(obj['message']);
                if (obj['status'] == 1) {
                    resetData();
                    getTransferData(0);
                }
            }
        });
    }
    //重置
    function resetData(id) {
        start = Array(1, 1, 1, 1, 1);
        $('.m2-manageResult-item').remove();
        $('.m2-manageResult-sum').hide();
    }
    //日历
    function ucDatepicker(locator) {
        $(locator).datetimepicker({
            lang: 'ch',
            timepicker: false,
            format: 'Y-m-d',
            allowBlank: true,
            onChangeDateTime: function () {
                $('.m2-manageSearchsel-time span').removeClass('m2-manSealink-sel');
                $('.m2-manageSearchsel-time span').addClass('m2-manSealink-unsel');
                if (time1 != $('#m2-manSeadate-start').val() || time2 != $('#m2-manSeadate-end').val()) {
                    resetData();
                    time1 = $('#m2-manSeadate-start').val();
                    time2 = $('#m2-manSeadate-end').val();
                    getTransferData(0);
                }
            }
        });
    }
    //提示框
    function infoDialog(text) {
        $('#dialog-info-bg').show();
        $('#dialog-info-div').show();
        $('#dialog-info-text').text(text);
    }
</script>
</body>
</html>